﻿using System.Collections.Generic;
using System.Configuration;

namespace IDesktop.Core
{
    public class Config
    {
        private static Configuration _manager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

        public static string Read(string key)
        {
            List<string> allKeys = new List<string>(_manager.AppSettings.Settings.AllKeys);
            string value = string.Empty;

            if (allKeys.Contains(key))
            {
                value = _manager.AppSettings.Settings[key].Value;
            }
            else
            {
                _manager.AppSettings.Settings.Add(key, value);
                _manager.Save();
            }

            return value;
        }

        public static void Write(string key, string value)
        {

            if (_manager.AppSettings.Settings[key] != null)
            {
                _manager.AppSettings.Settings.Remove(key);
            }
            _manager.AppSettings.Settings.Add(key, value);
            _manager.Save();
        }
    }
}
